home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / u_list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  17.5 KB  |  912 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "mode.h"
  15. #include "resources.h"
  16. #include "object.h"
  17. #include "paintop.h"
  18. #include "u_create.h"
  19. #include "u_list.h"
  20. #include "u_elastic.h"
  21. #include "u_undo.h"
  22.  
  23. void
  24. list_delete_arc(arc_list, arc)
  25.     F_arc      **arc_list, *arc;
  26. {
  27.     F_arc       *a, *aa;
  28.  
  29.     if (*arc_list == NULL)
  30.     return;
  31.     if (arc == NULL)
  32.     return;
  33.  
  34.     for (a = aa = *arc_list; aa != NULL; a = aa, aa = aa->next) {
  35.     if (aa == arc) {
  36.         if (aa == *arc_list)
  37.         *arc_list = (*arc_list)->next;
  38.         else
  39.         a->next = aa->next;
  40.         break;
  41.     }
  42.     }
  43.     arc->next = NULL;
  44. }
  45.  
  46. void
  47. list_delete_ellipse(ellipse_list, ellipse)
  48.     F_ellipse      **ellipse_list, *ellipse;
  49. {
  50.     F_ellipse       *q, *r;
  51.  
  52.     if (*ellipse_list == NULL)
  53.     return;
  54.     if (ellipse == NULL)
  55.     return;
  56.  
  57.     for (q = r = *ellipse_list; r != NULL; q = r, r = r->next) {
  58.     if (r == ellipse) {
  59.         if (r == *ellipse_list)
  60.         *ellipse_list = (*ellipse_list)->next;
  61.         else
  62.         q->next = r->next;
  63.         break;
  64.     }
  65.     }
  66.     ellipse->next = NULL;
  67. }
  68.  
  69. void
  70. list_delete_line(line_list, line)
  71.     F_line       *line, **line_list;
  72. {
  73.     F_line       *q, *r;
  74.  
  75.     if (*line_list == NULL)
  76.     return;
  77.     if (line == NULL)
  78.     return;
  79.  
  80.     for (q = r = *line_list; r != NULL; q = r, r = r->next) {
  81.     if (r == line) {
  82.         if (r == *line_list)
  83.         *line_list = (*line_list)->next;
  84.         else
  85.         q->next = r->next;
  86.         break;
  87.     }
  88.     }
  89.     line->next = NULL;
  90. }
  91.  
  92. void
  93. list_delete_spline(spline_list, spline)
  94.     F_spline      **spline_list, *spline;
  95. {
  96.     F_spline       *q, *r;
  97.  
  98.     if (*spline_list == NULL)
  99.     return;
  100.     if (spline == NULL)
  101.     return;
  102.  
  103.     for (q = r = *spline_list; r != NULL; q = r, r = r->next) {
  104.     if (r == spline) {
  105.         if (r == *spline_list)
  106.         *spline_list = (*spline_list)->next;
  107.         else
  108.         q->next = r->next;
  109.         break;
  110.     }
  111.     }
  112.     spline->next = NULL;
  113. }
  114.  
  115. void
  116. list_delete_text(text_list, text)
  117.     F_text      **text_list, *text;
  118. {
  119.     F_text       *q, *r;
  120.  
  121.     if (*text_list == NULL)
  122.     return;
  123.     if (text == NULL)
  124.     return;
  125.  
  126.     for (q = r = *text_list; r != NULL; q = r, r = r->next)
  127.     if (r == text) {
  128.         if (r == *text_list)
  129.         *text_list = text->next;
  130.         else
  131.         q->next = text->next;
  132.         break;
  133.     }
  134.     text->next = NULL;
  135. }
  136.  
  137. void
  138. list_delete_compound(list, compound)
  139.     F_compound      **list, *compound;
  140. {
  141.     F_compound       *c, *cc;
  142.  
  143.     if (*list == NULL)
  144.     return;
  145.     if (compound == NULL)
  146.     return;
  147.  
  148.     for (cc = c = *list; c != NULL; cc = c, c = c->next) {
  149.     if (c == compound) {
  150.         if (c == *list)
  151.         *list = (*list)->next;
  152.         else
  153.         cc->next = c->next;
  154.         break;
  155.     }
  156.     }
  157.     compound->next = NULL;
  158. }
  159.  
  160. void
  161. list_add_arc(arc_list, a)
  162.     F_arc      **arc_list, *a;
  163. {
  164.     F_arc       *aa;
  165.  
  166.     a->next = NULL;
  167.     if ((aa = last_arc(*arc_list)) == NULL)
  168.     *arc_list = a;
  169.     else
  170.     aa->next = a;
  171. }
  172.  
  173. void
  174. list_add_ellipse(ellipse_list, e)
  175.     F_ellipse      **ellipse_list, *e;
  176. {
  177.     F_ellipse       *ee;
  178.  
  179.     e->next = NULL;
  180.     if ((ee = last_ellipse(*ellipse_list)) == NULL)
  181.     *ellipse_list = e;
  182.     else
  183.     ee->next = e;
  184. }
  185.  
  186. void
  187. list_add_line(line_list, l)
  188.     F_line      **line_list, *l;
  189. {
  190.     F_line       *ll;
  191.  
  192.     l->next = NULL;
  193.     if ((ll = last_line(*line_list)) == NULL)
  194.     *line_list = l;
  195.     else
  196.     ll->next = l;
  197. }
  198.  
  199. void
  200. list_add_spline(spline_list, s)
  201.     F_spline      **spline_list, *s;
  202. {
  203.     F_spline       *ss;
  204.  
  205.     s->next = NULL;
  206.     if ((ss = last_spline(*spline_list)) == NULL)
  207.     *spline_list = s;
  208.     else
  209.     ss->next = s;
  210. }
  211.  
  212. void
  213. list_add_text(text_list, t)
  214.     F_text      **text_list, *t;
  215. {
  216.     F_text       *tt;
  217.  
  218.     t->next = NULL;
  219.     if ((tt = last_text(*text_list)) == NULL)
  220.     *text_list = t;
  221.     else
  222.     tt->next = t;
  223. }
  224.  
  225. void
  226. list_add_compound(list, c)
  227.     F_compound      **list, *c;
  228. {
  229.     F_compound       *cc;
  230.  
  231.     c->next = NULL;
  232.     if ((cc = last_compound(*list)) == NULL)
  233.     *list = c;
  234.     else
  235.     cc->next = c;
  236. }
  237.  
  238. void
  239. delete_line(old_l)
  240.     F_line       *old_l;
  241. {
  242.     list_delete_line(&objects.lines, old_l);
  243.     clean_up();
  244.     set_latestline(old_l);
  245.     set_action_object(F_DELETE, O_POLYLINE);
  246.     set_modifiedflag();
  247. }
  248.  
  249. void
  250. delete_arc(old_a)
  251.     F_arc       *old_a;
  252. {
  253.     list_delete_arc(&objects.arcs, old_a);
  254.     clean_up();
  255.     set_latestarc(old_a);
  256.     set_action_object(F_DELETE, O_ARC);
  257.     set_modifiedflag();
  258. }
  259.  
  260. void
  261. delete_ellipse(old_e)
  262.     F_ellipse       *old_e;
  263. {
  264.     list_delete_ellipse(&objects.ellipses, old_e);
  265.     clean_up();
  266.     set_latestellipse(old_e);
  267.     set_action_object(F_DELETE, O_ELLIPSE);
  268.     set_modifiedflag();
  269. }
  270.  
  271. void
  272. delete_text(old_t)
  273.     F_text       *old_t;
  274. {
  275.     list_delete_text(&objects.texts, old_t);
  276.     clean_up();
  277.     set_latesttext(old_t);
  278.     set_action_object(F_DELETE, O_TEXT);
  279.     set_modifiedflag();
  280. }
  281.  
  282. void
  283. delete_spline(old_s)
  284.     F_spline       *old_s;
  285. {
  286.     list_delete_spline(&objects.splines, old_s);
  287.     clean_up();
  288.     set_latestspline(old_s);
  289.     set_action_object(F_DELETE, O_SPLINE);
  290.     set_modifiedflag();
  291. }
  292.  
  293. void
  294. delete_compound(old_c)
  295.     F_compound       *old_c;
  296. {
  297.     list_delete_compound(&objects.compounds, old_c);
  298.     clean_up();
  299.     set_latestcompound(old_c);
  300.     set_action_object(F_DELETE, O_COMPOUND);
  301.     set_modifiedflag();
  302. }
  303.  
  304. void
  305. add_line(new_l)
  306.     F_line       *new_l;
  307. {
  308.     list_add_line(&objects.lines, new_l);
  309.     clean_up();
  310.     set_latestline(new_l);
  311.     set_action_object(F_ADD, O_POLYLINE);
  312.     set_modifiedflag();
  313. }
  314.  
  315. void
  316. add_arc(new_a)
  317.     F_arc       *new_a;
  318. {
  319.     list_add_arc(&objects.arcs, new_a);
  320.     clean_up();
  321.     set_latestarc(new_a);
  322.     set_action_object(F_ADD, O_ARC);
  323.     set_modifiedflag();
  324. }
  325.  
  326. void
  327. add_ellipse(new_e)
  328.     F_ellipse       *new_e;
  329. {
  330.     list_add_ellipse(&objects.ellipses, new_e);
  331.     clean_up();
  332.     set_latestellipse(new_e);
  333.     set_action_object(F_ADD, O_ELLIPSE);
  334.     set_modifiedflag();
  335. }
  336.  
  337. void
  338. add_text(new_t)
  339.     F_text       *new_t;
  340. {
  341.     list_add_text(&objects.texts, new_t);
  342.     clean_up();
  343.     set_latesttext(new_t);
  344.     set_action_object(F_ADD, O_TEXT);
  345.     set_modifiedflag();
  346. }
  347.  
  348. void
  349. add_spline(new_s)
  350.     F_spline       *new_s;
  351. {
  352.     list_add_spline(&objects.splines, new_s);
  353.     clean_up();
  354.     set_latestspline(new_s);
  355.     set_action_object(F_ADD, O_SPLINE);
  356.     set_modifiedflag();
  357. }
  358.  
  359. void
  360. add_compound(new_c)
  361.     F_compound       *new_c;
  362. {
  363.     list_add_compound(&objects.compounds, new_c);
  364.     clean_up();
  365.     set_latestcompound(new_c);
  366.     set_action_object(F_ADD, O_COMPOUND);
  367.     set_modifiedflag();
  368. }
  369.  
  370.  
  371. void
  372. change_line(old_l, new_l)
  373.     F_line       *old_l, *new_l;
  374. {
  375.     list_delete_line(&objects.lines, old_l);
  376.     list_add_line(&objects.lines, new_l);
  377.     clean_up();
  378.     old_l->next = new_l;
  379.     set_latestline(old_l);
  380.     set_action_object(F_CHANGE, O_POLYLINE);
  381.     set_modifiedflag();
  382. }
  383.  
  384. void
  385. change_arc(old_a, new_a)
  386.     F_arc       *old_a, *new_a;
  387. {
  388.     list_delete_arc(&objects.arcs, old_a);
  389.     list_add_arc(&objects.arcs, new_a);
  390.     clean_up();
  391.     old_a->next = new_a;
  392.     set_latestarc(old_a);
  393.     set_action_object(F_CHANGE, O_ARC);
  394.     set_modifiedflag();
  395. }
  396.  
  397. void
  398. change_ellipse(old_e, new_e)
  399.     F_ellipse       *old_e, *new_e;
  400. {
  401.     list_delete_ellipse(&objects.ellipses, old_e);
  402.     list_add_ellipse(&objects.ellipses, new_e);
  403.     clean_up();
  404.     old_e->next = new_e;
  405.     set_latestellipse(old_e);
  406.     set_action_object(F_CHANGE, O_ELLIPSE);
  407.     set_modifiedflag();
  408. }
  409.  
  410. void
  411. change_text(old_t, new_t)
  412.     F_text       *old_t, *new_t;
  413. {
  414.     list_delete_text(&objects.texts, old_t);
  415.     list_add_text(&objects.texts, new_t);
  416.     clean_up();
  417.     old_t->next = new_t;
  418.     set_latesttext(old_t);
  419.     set_action_object(F_CHANGE, O_TEXT);
  420.     set_modifiedflag();
  421. }
  422.  
  423. void
  424. change_spline(old_s, new_s)
  425.     F_spline       *old_s, *new_s;
  426. {
  427.     list_delete_spline(&objects.splines, old_s);
  428.     list_add_spline(&objects.splines, new_s);
  429.     clean_up();
  430.     old_s->next = new_s;
  431.     set_latestspline(old_s);
  432.     set_action_object(F_CHANGE, O_SPLINE);
  433.     set_modifiedflag();
  434. }
  435.  
  436. void
  437. change_compound(old_c, new_c)
  438.     F_compound       *old_c, *new_c;
  439. {
  440.     list_delete_compound(&objects.compounds, old_c);
  441.     list_add_compound(&objects.compounds, new_c);
  442.     clean_up();
  443.     old_c->next = new_c;
  444.     set_latestcompound(old_c);
  445.     set_action_object(F_CHANGE, O_COMPOUND);
  446.     set_modifiedflag();
  447. }
  448.  
  449. tail(ob, tails)
  450.     F_compound       *ob, *tails;
  451. {
  452.     F_arc       *a;
  453.     F_compound       *c;
  454.     F_ellipse       *e;
  455.     F_line       *l;
  456.     F_spline       *s;
  457.     F_text       *t;
  458.  
  459.     if (NULL != (a = ob->arcs))
  460.     for (; a->next != NULL; a = a->next);
  461.     if (NULL != (c = ob->compounds))
  462.     for (; c->next != NULL; c = c->next);
  463.     if (NULL != (e = ob->ellipses))
  464.     for (; e->next != NULL; e = e->next);
  465.     if (NULL != (l = ob->lines))
  466.     for (; l->next != NULL; l = l->next);
  467.     if (NULL != (s = ob->splines))
  468.     for (; s->next != NULL; s = s->next);
  469.     if (NULL != (t = ob->texts))
  470.     for (; t->next != NULL; t = t->next);
  471.  
  472.     tails->arcs = a;
  473.     tails->compounds = c;
  474.     tails->ellipses = e;
  475.     tails->lines = l;
  476.     tails->splines = s;
  477.     tails->texts = t;
  478. }
  479.  
  480. /*
  481.  * Make pointers in tails point to the last element of each list of l1 and
  482.  * Append the lists in l2 after those in l1. The tails pointers must be
  483.  * defined prior to calling append.
  484.  */
  485. append_objects(l1, l2, tails)
  486.     F_compound       *l1, *l2, *tails;
  487. {
  488.     if (tails->arcs)
  489.     tails->arcs->next = l2->arcs;
  490.     else
  491.     l1->arcs = l2->arcs;
  492.     if (tails->compounds)
  493.     tails->compounds->next = l2->compounds;
  494.     else
  495.     l1->compounds = l2->compounds;
  496.     if (tails->ellipses)
  497.     tails->ellipses->next = l2->ellipses;
  498.     else
  499.     l1->ellipses = l2->ellipses;
  500.     if (tails->lines)
  501.     tails->lines->next = l2->lines;
  502.     else
  503.     l1->lines = l2->lines;
  504.     if (tails->splines)
  505.     tails->splines->next = l2->splines;
  506.     else
  507.     l1->splines = l2->splines;
  508.     if (tails->texts)
  509.     tails->texts->next = l2->texts;
  510.     else
  511.     l1->texts = l2->texts;
  512. }
  513.  
  514. /* Cut is the dual of append. */
  515.  
  516. cut_objects(objects, tails)
  517.     F_compound       *objects, *tails;
  518. {
  519.     if (tails->arcs)
  520.     tails->arcs->next = NULL;
  521.     else
  522.     objects->arcs = NULL;
  523.     if (tails->compounds)
  524.     tails->compounds->next = NULL;
  525.     else
  526.     objects->compounds = NULL;
  527.     if (tails->ellipses)
  528.     tails->ellipses->next = NULL;
  529.     else
  530.     objects->ellipses = NULL;
  531.     if (tails->lines)
  532.     tails->lines->next = NULL;
  533.     else
  534.     objects->lines = NULL;
  535.     if (tails->splines)
  536.     tails->splines->next = NULL;
  537.     else
  538.     objects->splines = NULL;
  539.     if (tails->texts)
  540.     tails->texts->next = NULL;
  541.     else
  542.     objects->texts = NULL;
  543. }
  544.  
  545. append_point(x, y, point)
  546.     int            x, y;
  547.     F_point      **point;
  548. {
  549.     F_point       *p;
  550.  
  551.     if ((p = create_point()) == NULL)
  552.     return;
  553.  
  554.     p->x = x;
  555.     p->y = y;
  556.     p->next = NULL;
  557.     (*point)->next = p;
  558.     *point = p;
  559. }
  560.  
  561. num_points(points)
  562.     F_point       *points;
  563. {
  564.     int            n;
  565.     F_point       *p;
  566.  
  567.     for (p = points, n = 0; p != NULL; p = p->next, n++);
  568.     return (n);
  569. }
  570.  
  571. F_text           *
  572. last_text(list)
  573.     F_text       *list;
  574. {
  575.     F_text       *tt;
  576.  
  577.     if (list == NULL)
  578.     return NULL;
  579.  
  580.     for (tt = list; tt->next != NULL; tt = tt->next);
  581.     return tt;
  582. }
  583.  
  584. F_line           *
  585. last_line(list)
  586.     F_line       *list;
  587. {
  588.     F_line       *ll;
  589.  
  590.     if (list == NULL)
  591.     return NULL;
  592.  
  593.     for (ll = list; ll->next != NULL; ll = ll->next);
  594.     return ll;
  595. }
  596.  
  597. F_spline       *
  598. last_spline(list)
  599.     F_spline       *list;
  600. {
  601.     F_spline       *ss;
  602.  
  603.     if (list == NULL)
  604.     return NULL;
  605.  
  606.     for (ss = list; ss->next != NULL; ss = ss->next);
  607.     return ss;
  608. }
  609.  
  610. F_arc           *
  611. last_arc(list)
  612.     F_arc       *list;
  613. {
  614.     F_arc       *tt;
  615.  
  616.     if (list == NULL)
  617.     return NULL;
  618.  
  619.     for (tt = list; tt->next != NULL; tt = tt->next);
  620.     return tt;
  621. }
  622.  
  623. F_ellipse      *
  624. last_ellipse(list)
  625.     F_ellipse       *list;
  626. {
  627.     F_ellipse       *tt;
  628.  
  629.     if (list == NULL)
  630.     return NULL;
  631.  
  632.     for (tt = list; tt->next != NULL; tt = tt->next);
  633.     return tt;
  634. }
  635.  
  636. F_compound     *
  637. last_compound(list)
  638.     F_compound       *list;
  639. {
  640.     F_compound       *tt;
  641.  
  642.     if (list == NULL)
  643.     return NULL;
  644.  
  645.     for (tt = list; tt->next != NULL; tt = tt->next);
  646.     return tt;
  647. }
  648.  
  649. F_point           *
  650. last_point(list)
  651.     F_point       *list;
  652. {
  653.     F_point       *tt;
  654.  
  655.     if (list == NULL)
  656.     return NULL;
  657.  
  658.     for (tt = list; tt->next != NULL; tt = tt->next);
  659.     return tt;
  660. }
  661.  
  662. F_arc           *
  663. prev_arc(list, arc)
  664.     F_arc       *list, *arc;
  665. {
  666.     F_arc       *csr;
  667.  
  668.     if (list == arc)
  669.     return NULL;
  670.  
  671.     for (csr = list; csr->next != arc; csr = csr->next);
  672.     return csr;
  673. }
  674.  
  675. F_compound     *
  676. prev_compound(list, compound)
  677.     F_compound       *list, *compound;
  678. {
  679.     F_compound       *csr;
  680.  
  681.     if (list == compound)
  682.     return NULL;
  683.  
  684.     for (csr = list; csr->next != compound; csr = csr->next);
  685.     return csr;
  686. }
  687.  
  688. F_ellipse      *
  689. prev_ellipse(list, ellipse)
  690.     F_ellipse       *list, *ellipse;
  691. {
  692.     F_ellipse       *csr;
  693.  
  694.     if (list == ellipse)
  695.     return NULL;
  696.  
  697.     for (csr = list; csr->next != ellipse; csr = csr->next);
  698.     return csr;
  699. }
  700.  
  701. F_line           *
  702. prev_line(list, line)
  703.     F_line       *list, *line;
  704. {
  705.     F_line       *csr;
  706.  
  707.     if (list == line)
  708.     return NULL;
  709.  
  710.     for (csr = list; csr->next != line; csr = csr->next);
  711.     return csr;
  712. }
  713.  
  714. F_spline       *
  715. prev_spline(list, spline)
  716.     F_spline       *list, *spline;
  717. {
  718.     F_spline       *csr;
  719.  
  720.     if (list == spline)
  721.     return NULL;
  722.  
  723.     for (csr = list; csr->next != spline; csr = csr->next);
  724.     return csr;
  725. }
  726.  
  727. F_text           *
  728. prev_text(list, text)
  729.     F_text       *list, *text;
  730. {
  731.     F_text       *csr;
  732.  
  733.     if (list == text)
  734.     return NULL;
  735.  
  736.     for (csr = list; csr->next != text; csr = csr->next);
  737.     return csr;
  738. }
  739.  
  740. F_point           *
  741. prev_point(list, point)
  742.     F_point       *list, *point;
  743. {
  744.     F_point       *csr;
  745.  
  746.     if (list == point)
  747.     return NULL;
  748.  
  749.     for (csr = list; csr->next != point; csr = csr->next);
  750.     return csr;
  751. }
  752.  
  753. int
  754. object_count(list)
  755.     F_compound       *list;
  756. {
  757.     register int    cnt;
  758.     F_arc       *a;
  759.     F_text       *t;
  760.     F_compound       *c;
  761.     F_ellipse       *e;
  762.     F_line       *l;
  763.     F_spline       *s;
  764.  
  765.     cnt = 0;
  766.     for (a = list->arcs; a != NULL; a = a->next, cnt++);
  767.     for (t = list->texts; t != NULL; t = t->next, cnt++);
  768.     for (c = list->compounds; c != NULL; c = c->next, cnt++);
  769.     for (e = list->ellipses; e != NULL; e = e->next, cnt++);
  770.     for (l = list->lines; l != NULL; l = l->next, cnt++);
  771.     for (s = list->splines; s != NULL; s = s->next, cnt++);
  772.     return (cnt);
  773. }
  774.  
  775. set_tags(list, tag)
  776.     F_compound       *list;
  777.     int            tag;
  778. {
  779.     F_arc       *a;
  780.     F_text       *t;
  781.     F_compound       *c;
  782.     F_ellipse       *e;
  783.     F_line       *l;
  784.     F_spline       *s;
  785.  
  786.     for (a = list->arcs; a != NULL; a = a->next) {
  787.     mask_toggle_arcmarker(a);
  788.     a->tagged = tag;
  789.     mask_toggle_arcmarker(a);
  790.     }
  791.     for (t = list->texts; t != NULL; t = t->next) {
  792.     mask_toggle_textmarker(t);
  793.     t->tagged = tag;
  794.     mask_toggle_textmarker(t);
  795.     }
  796.     for (c = list->compounds; c != NULL; c = c->next) {
  797.     mask_toggle_compoundmarker(c);
  798.     c->tagged = tag;
  799.     mask_toggle_compoundmarker(c);
  800.     }
  801.     for (e = list->ellipses; e != NULL; e = e->next) {
  802.     mask_toggle_ellipsemarker(e);
  803.     e->tagged = tag;
  804.     mask_toggle_ellipsemarker(e);
  805.     }
  806.     for (l = list->lines; l != NULL; l = l->next) {
  807.     mask_toggle_linemarker(l);
  808.     l->tagged = tag;
  809.     mask_toggle_linemarker(l);
  810.     }
  811.     for (s = list->splines; s != NULL; s = s->next) {
  812.     mask_toggle_splinemarker(s);
  813.     s->tagged = tag;
  814.     mask_toggle_splinemarker(s);
  815.     }
  816. }
  817.  
  818. void
  819. get_links(llx, lly, urx, ury)
  820.     int            llx, lly, urx, ury;
  821. {
  822.     F_line       *l;
  823.     F_point       *a;
  824.     F_linkinfo       *j, *k;
  825.  
  826.     j = NULL;
  827.     for (l = objects.lines; l != NULL; l = l->next)
  828.     if (l->type == T_POLYLINE) {
  829.         a = l->points;
  830.         if (point_on_perim(a, llx, lly, urx, ury)) {
  831.         if ((k = new_link(l, a, a->next)) == NULL)
  832.             return;
  833.         if (j == NULL)
  834.             cur_links = k;
  835.         else
  836.             j->next = k;
  837.         j = k;
  838.         if (k->prevpt != NULL)
  839.             k->two_pts = (k->prevpt->next == NULL);
  840.         continue;
  841.         }
  842.         if (a->next == NULL)/* single point, no need to check further */
  843.         continue;
  844.         a = last_point(l->points);
  845.         if (point_on_perim(a, llx, lly, urx, ury)) {
  846.         if ((k = new_link(l, a, prev_point(l->points, a))) == NULL)
  847.             return;
  848.         if (j == NULL)
  849.             cur_links = k;
  850.         else
  851.             j->next = k;
  852.         j = k;
  853.         if (k->prevpt != NULL)
  854.             k->two_pts = (prev_point(l->points, k->prevpt) == NULL);
  855.         continue;
  856.         }
  857.     }
  858. }
  859.  
  860. #define LINK_TOL 3
  861.  
  862. int
  863. point_on_perim(p, llx, lly, urx, ury)
  864.     F_point       *p;
  865.     int            llx, lly, urx, ury;
  866. {
  867.     return ((abs(p->x - llx) <= LINK_TOL && p->y >= lly - LINK_TOL
  868.          && p->y <= ury + LINK_TOL) ||
  869.         (abs(p->x - urx) <= LINK_TOL && p->y >= lly - LINK_TOL
  870.          && p->y <= ury + LINK_TOL) ||
  871.         (abs(p->y - lly) <= LINK_TOL && p->x >= llx - LINK_TOL
  872.          && p->x <= urx + LINK_TOL) ||
  873.         (abs(p->y - ury) <= LINK_TOL && p->x >= llx - LINK_TOL
  874.          && p->x <= urx + LINK_TOL));
  875. }
  876.  
  877. void
  878. adjust_links(mode, links, dx, dy, cx, cy, sx, sy, copying)
  879.     int            mode;
  880.     F_linkinfo       *links;
  881.     int        dx, dy;        /* delta */
  882.     int        cx, cy;        /* center of scale - NOT USED YET */
  883.     float    sx, sy;        /* scale factor - NOT USED YET */
  884.     int            copying;
  885. {
  886.     F_linkinfo       *k;
  887.     F_line       *l;
  888.  
  889.     if (mode != SMART_OFF)
  890.     for (k = links; k != NULL; k = k->next) {
  891.         if (copying) {
  892.         l = copy_line(k->line);
  893.         list_delete_line(&objects.lines, k->line);
  894.         list_add_line(&saved_objects.lines, k->line);
  895.         list_add_line(&objects.lines, l);
  896.         } else {
  897.         mask_toggle_linemarker(k->line);
  898.         draw_line(k->line, ERASE);
  899.         }
  900.         if (mode == SMART_SLIDE && k->prevpt != NULL) {
  901.         if (k->endpt->x == k->prevpt->x)
  902.             k->prevpt->x += dx;
  903.         else
  904.             k->prevpt->y += dy;
  905.         }
  906.         k->endpt->x += dx;
  907.         k->endpt->y += dy;
  908.         draw_line(k->line, PAINT);
  909.         mask_toggle_linemarker(k->line);
  910.     }
  911. }
  912.